﻿ using System.Runtime.InteropServices;
using RayDen.Library.Components.Surface;
using RayDen.Library.Core.Primitives;
using RayDen.Library.Entity.Scene;

namespace RayDen.MegaRay.Core
{
    [StructLayout(LayoutKind.Explicit, Size = 128)]
    public struct PathVertexData
    {
        /// <summary>
        /// [Surface Geometry]
        /// </summary>
        [FieldOffset(0)]
        public int MaterialID;

        /// <summary>
        /// [Common]
        /// </summary>
        [FieldOffset(4)]
        public Point HitPoint;

        //Surface Geometry

        /// <summary>
        /// [Surface Geometry]
        /// </summary>
        [FieldOffset(16)]         
        public Normal GeoNormal;
        /// <summary>
        /// [Surface Geometry]
        /// </summary>
        [FieldOffset(28)]
        public Normal ShadingNormal;

        /// <summary>
        /// [Surface Geometry]
        /// </summary>
        [FieldOffset(40)]
        public UV SurfaceHit;

        /// <summary>
        /// [Surface Geometry]
        /// </summary>
        [FieldOffset(48)] 
        public Vector IncomingDirection;

        /// <summary>
        /// [Surface Geometry]
        /// </summary>
        [FieldOffset(60)] 
        public Vector OutgoingDirection;

        /// <summary>
        /// [Surface Geometry]
        /// </summary>
        [FieldOffset(72)] 
        public float Pdf;

        /// <summary>
        /// [Surface Geometry]
        /// </summary>
        [FieldOffset(84)] 
        public RgbSpectrum BsdfSample;
        /// <summary>
        /// [Surface Geometry]
        /// </summary>
        [FieldOffset(96)]
        public RgbSpectrum Alpha;
        /// <summary>
        /// [Surface Geometry]
        /// </summary>
        [FieldOffset(108)]
        public RgbSpectrum Color;
        /// <summary>
        /// [Surface Geometry]
        /// </summary>
        [FieldOffset(109)] 
        public byte Flags;
        /// <summary>
        /// [Surface Geometry]
        /// </summary>
        [FieldOffset(110)] 
        public ISurfaceMaterial Brdf;
        /// <summary>
        /// [Surface Geometry]
        /// </summary>
        [FieldOffset(118)]
        public MaterialInfo MaterialInfo;

        // Light source

        /// <summary>
        /// [Lightsource]
        /// </summary>
        [FieldOffset(0)]
        public int LightId;
        /// <summary>
        /// [Lightsource]
        /// </summary>
        [FieldOffset(16)]
        public RgbSpectrum Emission;

        // Volume

        /// <summary>
        /// [Volume]
        /// </summary>
        [FieldOffset(0)]
        public int VolumeId;

        /// <summary>
        /// [Volume]
        /// </summary>
        [FieldOffset(16)] 
        public RgbSpectrum SigmaA;
        /// <summary>
        /// [Volume]
        /// </summary>
        [FieldOffset(28)] 
        public RgbSpectrum SigmaS;
        /// <summary>
        /// [Volume]
        /// </summary>
        [FieldOffset(40)] 
        public RgbSpectrum SigmaE;


        //Camera
        /// <summary>
        /// [Camera]
        /// </summary>
        [FieldOffset(0)] 
        public Point CameraPoint;

        /// <summary>
        /// [Camera]
        /// </summary>
        [FieldOffset(12)]
        public Vector CameraDirection;

        /// <summary>
        /// [Camera]
        /// </summary>
        [FieldOffset(24)]
        public UV Lens;

        /// <summary>
        /// [Camera]
        /// </summary>
        [FieldOffset(32)]
        public float Time;
    }
}